#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>


int main()
{

  pid_t pid = fork();

  if(pid < 0)
     exit(1);
  if(pid > 0)
     exit(0);

setsid();

for(int i = 0 ; i < 101122; i++)
{
    close(i);
}      	

chdir("/");

umask(0);

int num = 0;

while(1)
{

unsigned int fd = open("/tmp/mylog.log", O_CREAT|O_RDWR|O_APPEND, 06666);

if(fd > 0)
{

  char content[128];

  sprintf(content,"print my log ----->%d\n",num);

  write(fd, content, strlen(content));

  close(fd);

  num++;

}

sleep(2);

}


return 0;
}
